[WPF] SelectionChanged of a child ListBox

Posted by quimbs on Stack Overflow See other posts from Stack Overflow or by quimbs
Published on 2010-03-09T23:33:54Z Indexed on 2010/03/12 12:57 UTC
Read the original article Hit count: 425

Filed under:
|
|
|

Hi,

I have a ListBox bound to an ObservableCollection with an ItemTemplate that contains another ListBox. First of all, I tried to get the last selected item of all the listboxes (either the parent and the inner ones) from my MainWindowViewModel this way:

public object SelectedItem
{
    get { return this.selectedItem; }
    set 
    {
        this.selectedItem = value;
        base.NotifyPropertyChanged("SelectedItem");
    }
}

So, for example, in the DataTemplate of the items of the parent ListBox I've got this:

<ListBox ItemsSource="{Binding Tails}"
 SelectedItem="{Binding Path=DataContext.SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>

The problem now, is that when I select an item from the parent ListBox and then an item from a child listbox, I get this:

http://i40.tinypic.com/j7bvig.jpg

As you can see, two items are selected at the same time. How can I solve that?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about listbox